package com.hiyee.idWorker;

import com.hiyee.idWorker.extend.SnowflakeResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(SnowflakeResource.class)
public class SnowflakeAutoConfiguration {
    @Autowired
    SnowflakeResource snowflakeResource;

    @Bean
    @ConditionalOnMissingBean
    public SnowflakeIdUtil snowflakeIdUtil() {
        return new SnowflakeIdUtil(snowflakeResource.getMachineId(), snowflakeResource.getDataCenterId());
    }
}
